package com.googlecode.todo_robot.persistence.model;

import com.google.appengine.api.datastore.Key;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Date;

/**
 * @author Fuad Ibrahimov
 * @since 19.12.2009
 */
@Entity
public class TodoItem {

  public TodoItem(String owner, String text) {
    this.owner = owner;
    this.text = text;
  }

  protected TodoItem() {
  }

  public Key getKey() {
    return key;
  }

  public String getOwner() {
    return owner;
  }

  public void setOwner(String owner) {
    this.owner = owner;
  }

  public String getText() {
    return text;
  }

  public void setText(String text) {
    this.text = text;
  }

  public String getWaveId() {
    return waveId;
  }

  public void setWaveId(String waveId) {
    this.waveId = waveId;
  }

  public String getWaveletId() {
    return waveletId;
  }

  public void setWaveletId(String waveletId) {
    this.waveletId = waveletId;
  }

  public String getBlipId() {
    return blipId;
  }

  public void setBlipId(String blipId) {
    this.blipId = blipId;
  }

  public String getNotes() {
    return notes;
  }

  public void setNotes(String notes) {
    this.notes = notes;
  }

  public Date getDueDate() {
    return new Date(dueDate.getTime());
  }

  public void setDueDate(Date dueDate) {
    this.dueDate = new Date(dueDate.getTime());
  }

  public Priority getPriority() {
    return priority;
  }

  public void setPriority(Priority priority) {
    this.priority = priority;
  }

  public boolean isDone() {
    return done;
  }

  public void setDone(boolean done) {
    this.done = done;
  }

  public Timestamp getCreatedAt() {
    return new Timestamp(createdAt.getTime());
  }

  public Timestamp getUpdatedAt() {
    return new Timestamp(updatedAt.getTime());
  }

  @Override
  public String toString() {
    return "TodoItem{" + "key=" + key + ", owner=[" + owner + "], todo=[" + text + "]}";
  }

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Key key;

  @Basic
  private String owner;

  @Basic
  private String waveId;

  @Basic
  private String waveletId;

  @Basic
  private String blipId;

  @Basic
  private String text;

  @Basic
  private String notes;

  @Basic
  private Date dueDate;

  @Basic
  @Enumerated(value = EnumType.STRING)
  private Priority priority;

  @Basic
  private boolean done;

  @Temporal(TemporalType.TIMESTAMP)
  private Timestamp createdAt;

  @Temporal(TemporalType.TIMESTAMP)
  private Timestamp updatedAt;

  public enum Priority {
    HIGH, MEDIUM, LOW, NONE // TODO - implement sorting by priority: Comparable and/or DB sorting by ordinal
  }  
}
